package com.jcwx.game.login;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.jcwx.game.domain.AreaInfo;
import com.jcwx.game.domain.LoginGameInfo;
import com.jcwx.game.util.BocHttpClient;

/**
 * 登录游戏
 * 
 * @author csp
 * 
 */
public class LoginGame {

	

	public LoginGameInfo loginGameInfo(AreaInfo areaInfo) {

		/**
		 * /front/game-login.action
		 * 参数：token_key（令牌），areaId（大区ID），ver（版本号），ln（语言）
		 * 返回：{"actionErrors":[],"actionMessages"
		 * :[],"areaId":126,"code":0,"ln":null,"loginSign":
		 * {"ip":"54.72.238.63",
		 * "key":"1eef88571bb2c1a4b060c35fc62f154c","phoneId":"","port":9001,
		 * "ptAreaId"
		 * :126,"ptCode":"wonder","time":"1400922114935","uid":null,"userName"
		 * :"51893","userType":0},
		 * "sig":null,"token_key":"F1A02AE2113347A6A68AF3EA272D70C6"
		 * ,"ver":"2.0.16"} [139160, , 1401096708734,
		 * 6b04cc1a74e524af78d0b52226feb5b9, 1, 0, wonder, 68, Windows]
		 */

		String url = "http://192.168.1.250:8881/front/game-login.action";
		Map<String, String> params = new HashMap<String, String>();
		// 获得大区放回的 token_key
		params.put("token_key", areaInfo.getToken_key());
		params.put("areaId", "68"); // 195 机器
		params.put("ver", "");
		params.put("ln", "");
		String jsonObject = "";
		try {
			jsonObject = BocHttpClient.sendPost(url, params);
			System.out.println(jsonObject);
		} catch (Exception e) {
			e.printStackTrace();
		}

		LoginGameInfo loginGameInfo = JSON.parseObject(jsonObject,
				LoginGameInfo.class);

		return loginGameInfo;

	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		LoginGame loginGame=new LoginGame();
		

		LoginGameInfo loginGameInfo = loginGame.loginGameInfo(null);
		
		System.out.println(loginGameInfo.getLoginSign().getTime());

	}

}
